﻿/**
* Description here..
* @author crlnet
* @version 1.1
*/

package com.crlclr{
	
	import com.crl.ui.controls.Component;
	import com.crl.utils.StringUtil;
	import com.crlclr.common.LoaderAdapter;
	import com.crlclr.data.*;
	import com.crlclr.data.qzone.PictureVO;
	import com.crlclr.events.*;
	import com.crlclr.managers.*;
	import com.crlclr.ui.*;
	import com.crlclr.utils.FileType;
	import com.crlclr.utils.QSize;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.DropShadowFilter;
	
	public class Page extends Component{
		public var book:Book;
		public var index:int;
		private var _data:IPicture;
		private var loader:Loader;

		
		public var defaultSize:QSize = QSize.Empty;
		public var isLoaded:Boolean = false;
		
		private var tips:QToolTip;
		public function Page(book:Book) {
			this.book=book;
			super();
			
			this.filters=[new DropShadowFilter(4.0,60)]
		}
		
		/**
		 * 创建载体;
		 */
		protected override function create():void {			
			this.loader = new Loader();
			addChild(loader);
			tips=new QToolTip(this.loader,"未知");
		}
		
		protected override function bind():void {
			this.loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHander);
		}
		protected function removeEvent():void {
			this.loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, completeHander);
		}
		
		public function putin():void {
			if (isLoaded) return;
			var adapter:LoaderAdapter = new LoaderAdapter(loader, this._data.path, this.toString());
			
			LoaderManager.getInstance().addItem(adapter,book.firstLoaded);
		}
		public function out():void {
			
		}
		
		private function completeHander(event:Event):void {
			isLoaded = true;
			this.defaultSize = new QSize(this.width, this.height);
			
			this.dispatchEvent(event.clone());
		}
		
		
		
		
		
		/**
		* 数据属性;
		* @param	data
		* @return
		*/
		public function set data(data:IPicture):void{
			this._data=data;
			if(data){
				
				var t:String=data.name;
				var desc:String=StringUtil.trim(data.desc);
				if(desc !=""){
					t+="_"+desc;
				}
				
				
				this.tips.setTexto(t);
			}
		}
		public function get data():IPicture{
			return this._data;
		}
		
	
		public function get Type():String {
			return FileType.BITMAP;
		}
		
		
		public override function toString():String {
			return "page"+index+" Sprite";
		}
	}
	
}